package com.hllxd.hism.star.basic.service.controller;


import com.alibaba.fastjson.JSON;
import com.hllxd.hism.star.basic.service.model.metric.KpiReportEntity;
import com.hllxd.hism.star.basic.service.service.KpiReportService;
import com.hllxd.hism.star.basic.service.util.ResultUtils;
import com.hllxd.hism.star.basic.service.util.Utils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


/**
 * 对外api统一controller
 */
@RestController
@RequestMapping("/basic/v1/kpi")
@Slf4j
public class KpiController {

    @Autowired
    private KpiReportService kpiReportService;


    /**
     * #{groupId}, #{source}, #{metricId}, #{metricValue}, #{reportDate}
     * */
    @RequestMapping(value = "/addReport", method = RequestMethod.POST)
    public Object addReport(@RequestBody KpiReportEntity dto) {
        try {
            log.info("addReport：" + JSON.toJSONString(dto));
            Long result = kpiReportService.setReport(dto);
            if (result == null) {
                return ResultUtils.errorResult("1011003", "API上报数据失败");
            }
            return ResultUtils.result(result);
        } catch (Exception e) {
            log.error("[{}] exception: {}.", Utils.getTraceID(), e, e);
            return ResultUtils.errorResult("1011002", "API上报数据异常:" + e);
        }
    }
}
